#include<bits/stdc++.h>
#define ll long long
#define for1(i,a,b) for(ll i=a;i<=b;i++)
using namespace std;
inline ll re()
{
    ll s=0,f=1; char c=getchar();
    while(!isdigit(c)) {if(c=='-')f=-1;c=getchar();}
    while(isdigit(c)) {s=s*10+c-'0';c=getchar();}
    return f*s;
}
inline void wr(ll x)
{
    if(x<0) {putchar('-');wr(-x);return;}
    if(x>9) wr(x/10);
    putchar(x%10+'0');
}
const ll N=2e4+10;
ll T,n,a[N],f[N][3][3];
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout); 
    T=re();
    while(T--)
    {
        memset(f,0,sizeof(f));
        n=re();
        for1(i,1,n) a[i]=re();
        for1(i,2,n)
        {
            f[i][0][0]=max(f[i-1][0][0],f[i-1][0][1]);
            f[i][1][1]=max(f[i-1][1][0],f[i-1][1][1]);
            if(a[i]==a[i-1]) f[i][0][0]+=a[i],f[i][1][1]+=a[i];
            ll x=0;
            for(ll j=i-1;j>=1;j--)
            {
                for1(k,0,1)
                {
                    if(a[i]==a[j-1]) f[i][k][k^1]=max(f[i][k][k^1],f[j][k^1][k]+x+a[i]);
                    else f[i][k][k^1]=max(f[i][k][k^1],f[j][k^1][k]+x);
                }
                if(a[j]==a[j-1]) x+=a[j];
            }
        }
        ll ma=-4e18;
        for1(j,0,1) for1(k,0,1) ma=max(ma,f[n][j][k]);
        cout<<ma<<endl;
    }
    return 0;
}
/*
3
3
1 2 1
4
1 2 3 4
8
3 5 2 5 1 2 1 4
*/